package cn.com.hhrcw.utils.edu;

import cn.com.hhrcw.entity.CvUserEduInfo;
import cn.com.hhrcw.service.ICvUserEduInfoService;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author lixingxing
 */
@Component
public class EduLabelUtil {

    @Autowired
    private ICvUserEduInfoService cvUserEduInfoService;

    /**
     * 获取第一学位
     *
     * @param resumeId
     * @param lanType
     * @return
     */
    public String getFirstDegree(String resumeId, int lanType) {
        //教育经历
        LambdaQueryWrapper<CvUserEduInfo> userEduInfoQuery = new LambdaQueryWrapper<>();
        userEduInfoQuery.eq(CvUserEduInfo::getDelFlag, false).eq(CvUserEduInfo::getResumeId, resumeId)
            .orderByDesc(CvUserEduInfo::getEduLevel)
            .last("limit 1");
        CvUserEduInfo one = cvUserEduInfoService.getOne(userEduInfoQuery);
        if (one == null) {
            return "无";
        }
        return geDegree(one.getR1(), lanType);
    }

    /**
     * 获取学位
     *
     * @param degree
     * @param lanType
     * @return
     */
    public String geDegree(String degree, int lanType) {
        String degreeText = "/";
        final String[] degreeTextArr = {"/", "学士", "硕士", "博士"};
        final String[] degreeTexEntArr = {"/", "scholar", "master", "doctor"};
        if (StringUtils.isNotBlank(degree)) {
            if (lanType == 0) {
                degreeText = degreeTextArr[Convert.toInt(degree)];
            } else {
                degreeText = degreeTexEntArr[Convert.toInt(degree)];
            }
        }
        return degreeText;
    }

    /**
     * 获取学历
     *
     * @param eduLevel
     * @return
     */
    public String getEduLevel(Integer eduLevel) {
       return this.getEduLevel(eduLevel, 0);
    }

    public String getEduLevel(Integer eduLevel, int lanType) {
        final String[][] eduLevels = {
            {"初中", "高中", "中专/中技", "大专", "本科", "研究生", "MBA/EMBA", "博士"},
            {"junior middle school", "high school", "secondary education", "junior college", "undergraduate", "postgraduate", "MBA/EMBA", "doctor"}
        };
        return eduLevel == null ? "无" : eduLevels[lanType][eduLevel];

    }
}
